package main

import (
	"log"
	"time"
)

func handler(msgCh, quitCh chan int) {
	for i := 0; i < 10; i++ {
		time.Sleep(time.Second)
		if i < 6 {
			msgCh <- i
		} else {
			quitCh <- 0
		}
	}
}

func main() {
	msgCh := make(chan int)
	quitCh := make(chan int)
	go handler(msgCh, quitCh)
	val := 0
	for {
		select {
		case val = <-msgCh:
			log.Println("接收到值:", val)
		case <-quitCh:
			log.Println("quit:", <-quitCh)
			return
		}
	}
	// log.Println("main done")/
}
